package com.example.neusoft.yuejian.Fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian.Base.BaseFragment;
import com.example.neusoft.yuejian.Base.BaseListener;
import com.example.neusoft.yuejian.Base.BaseModel;

import com.example.neusoft.yuejian.Bean.MyBean;
import com.example.neusoft.yuejian.R;
import com.squareup.picasso.Picasso;


import retrofit2.Call;

public class MyFragment extends BaseFragment implements View.OnClickListener {
    private MyBean mine;
    private TextView my_name;
    private ImageView my_pic;
    private int id;
    private Context context;
    private SharedPreferences sp ;
    @Override
    public void onClick(View v) {

    }

    @Override
    public int getLayoutFile() {
        return R.layout.activity_my;
    }

    @Override
    public void initView() {
        context=getActivity();
        sp=context.getSharedPreferences("User", Context.MODE_PRIVATE);
        id= sp.getInt("id",0);
        my_name=view.findViewById(R.id.my_name);
        my_pic=view.findViewById(R.id.my_pic);
    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
                 getMine(id);
    }
    private void getMine(int uid ){
        BaseModel<MyBean> model = new BaseModel<>();
        Call<MyBean> call = model.service.getMine(uid);
        model.callEnqueue(call, list);
    }
 BaseListener<MyBean> list=new BaseListener<MyBean>() {
     @Override
     public void onResponse(MyBean myBean) {
         mine=myBean;
         my_name.setText(mine.getUname());
         Picasso.with(getActivity()).load("http://172.19.181.175/YueJian/public/static/img/userimg/"
                 +mine.getUpic()).into(my_pic);
         sp =context.getSharedPreferences("User", Context.MODE_PRIVATE);
         SharedPreferences.Editor edit = sp.edit();
         edit.putString("username", mine.getUname());
         edit.commit();
     }

     @Override
     public void onFail(String msg) {

     }
 };

}
